/**
 * Book.java
 * -- Short Description Here --
 *
 * @author:  John Thomason
 *  Course:  CS223
 *  Assign:
 * Seminar:
 *    Date:  Feb 17, 2009
 */

// Assigned Package
package libman;

// Package Imports
import java.io.*;

/**
 * Book Class
 */
public class Book
implements Serializable
{
    //Lengths
    public static final int ID_MAX_LEN      = 10;
    public static final int TITLE_MAX_LEN   = 255;
    public static final int AUTHOR_MAX_LEN  = 40;
    public static final int SUMMARY_MAX_LEN = 4096;

    //Field Enum
    public enum Field {
        ID,
        TITLE,
        AUTHOR,
        SUMMARY
    }//Fields Enum
    
    //Instance Variables
    String id, title, author, summary;

    //Constructors
    public Book(String id,
                String title,
                String author,
                String summary)
    throws LibManException
    {
        if (id.trim().isEmpty())
        throw new LibManException("Book::ID field can NOT be NULL...");

        if (title.trim().isEmpty())
        throw new LibManException("Book::Title field can NOT be NULL...");

        if (author.trim().isEmpty()) 
        throw new LibManException("Book::Author field can NOT be NULL...");

        setId(id);
        setTitle(title);
        setAuthor(author);
        setSummary(summary);
    }//Book Constructor

    public String getId() {
        return id.trim();
    }
    public void setId(String id) {
        this.id = id.length() > ID_MAX_LEN   ?
                  id.substring(0,ID_MAX_LEN) :
                  id;
    }

    public String getTitle() {
        return title.trim();
    }
    public void setTitle(String title) {
        this.title = title.length() > TITLE_MAX_LEN    ?
                     title.substring(0, TITLE_MAX_LEN) :
                     title;
    }

    public String getAuthor() {
        return author.trim();
    }
    public void setAuthor(String author) {
        this.author = author.length() > AUTHOR_MAX_LEN    ?
                      author.substring(0, AUTHOR_MAX_LEN) :
                      author;
    }

    public String getSummary() {
        return summary.trim();
    }
    public void setSummary(String summary) {
        this.summary = summary.length() > SUMMARY_MAX_LEN    ?
                       summary.substring(0, SUMMARY_MAX_LEN) :
                       summary;
    }

    @Override
    public String toString() {
        return String.format("Title: %s :: %s\nAuthor: %s\nSummary: %s\n",
                                  title,   id,     author,     summary);
    }

}//Book Class
